<?php
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
	header("Cache-Control: no-store, no-cache, must-revalidate"); 
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	error_reporting(E_ALL);
	ini_set('display_errors', 'On');
	include "inc/inc_doctype.php";
	include "inc/inc_head.php";
	include "inc/inc_common.php";
	include "inc/inc_secret.php";
?>
<body>
<div class="container-fluid">
 <div class="span12">
 <?php
	$servername = $_SESSION['debyvas'];
	$username = $_SESSION['chtosi'];
	$password = $_SESSION['kelovazis'];
	$dbname = $_SESSION['desi'];

	// Create connection
	$conn = new mysqli($servername, $username, $password, $dbname);
	// Check connection
	if ($conn->connect_error) {
		die("Connection failed: " . $conn->connect_error);
	} 
	$sql = "SELECT  `rr`.id AS iid, `rr`.nazov, `rr`.vlastny, DATE_FORMAT( `rr`.datum ,  '%d.%m.%Y' ) AS datum, `rr`.objem FROM `eLiquid.Data.Recept` AS rr";
	$result = $conn->query($sql);
	?>
	<table style="width:900px;" cellpadding="0" cellspacing="0" border="0">
	<?
	if ($result->num_rows > 0) {
		while($row = $result->fetch_assoc()) {
			$id=$row["iid"];
			$datum=$row["datum"];
			$objem = (float) $row["objem"];
			$objem = number_format($objem, 2, ',', ' ');
			echo '<tr class="tr_' .str_replace('.','',$datum). '">';
			echo '<td class="grpSeparator active" style="width:160px !important;">'. $row["nazov"]. '</td><td class="grpSeparator"><span style="float:left;padding-left:10px;color:yellow;">' .$row["datum"]. ' - '. $objem .'&nbsp;ml.</span></td>';
			echo '</tr>';
			$sql2="SELECT `pr`.pocetkvapiek,`pr`.kvapky,`pp`.vyrobca,`pp`.obchod, `pp`.objem,`pp`.typ,`pp`.nazov AS nn FROM `eliquid.data.receptprisady` pr ";
			$sql2=$sql2." left join `eliquid.cis.prisady` pp on `pr`.PrisadaCisId=`pp`.id";
			$sql2=$sql2." where receptid=".$id;
			$conn2 = new mysqli($servername, $username, $password, $dbname);
			if ($conn2->connect_error) {
				die("Connection failed: " . $conn2->connect_error);
			}
			$result2 = $conn2->query($sql2);	
				if ($result2->num_rows > 0) {
				while($row2 = $result2->fetch_assoc()) {			
					echo "<tr class=\"childs\"><td colspan=\"2\"><table>";
					echo "<tr><td>".$row2["nn"]."</td>";
					echo "</tr></table></td></tr>";
				}
			}
			$conn2->close();
			
		}
	} else {
		echo "<tr><td>0 results</td></tr>";
	}
	echo "</table>";
	$conn->close();
?>
 </div>
 </div>
</body>
</html>